#define PC

using System;
using System.Collections.Generic;
using System.Diagnostics;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace TimeWar
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class TitleScreen : CurrGameComponent
    {

        private Game timeWarGame;

        private SpriteBatch spriteBatch;
        private Vector2 screenpos, origin, texturesize;
        private Texture2D background;
        private int screenheight;

        SpriteFont Font1;
        Vector2 FontPos;


        public TitleScreen(TimeWar game)
            : base(game)
        {
            // TODO: Construct any child components here
            timeWarGame = game;
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            base.gameComponentInitialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here


            base.gameComponentUpdate(gameTime);
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent(GraphicsDevice graphicsDevice)
        {

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(graphicsDevice);
            Font1 = timeWarGame.Content.Load<SpriteFont>("Courier New");
            

            // TODO: use this.Content to load your game content here
            //Content.
            background = timeWarGame.Content.Load<Texture2D>("Images\\TitleScreen");
            screenheight = graphicsDevice.Viewport.Height;
            int screenwidth = graphicsDevice.Viewport.Width;
            // Set the origin so that we're drawing from the 
            // center of the top edge.
            origin = new Vector2(0, 0);
            // Set the screen position to the center of the screen.
            FontPos = new Vector2(screenwidth / 2, screenheight / 2);
            //screenpos = new Vector2(0, 0);
            screenpos = new Vector2(screenwidth / 2 - (background.Width / 2), screenheight / 2 - (background.Height / 2));

        }

        public override void Draw(GraphicsDeviceManager graphics, GameTime gameTime)
        {
#if PC
            Trace.WriteLine("[" + DateTime.Now + "]: Calling TitleScreen.Draw() method.");
#endif

            graphics.GraphicsDevice.Clear(Color.Black);

            // TODO: Add your drawing code here
            spriteBatch.Begin();

            spriteBatch.Draw(background, screenpos, null,
                         Color.White, 0, origin, 1, SpriteEffects.None, 0f);

            // Draw Hello World
            string output = "Time War: v0.1";

            // Find the center of the string
            Vector2 FontOrigin = Font1.MeasureString(output) / 2;
            // Draw the string
            spriteBatch.DrawString(Font1, output, FontPos, Color.LightGreen,
                0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);

            spriteBatch.End();

#if PC
            Trace.WriteLine("[" + DateTime.Now + "]: Exiting TitleScreen.Draw() method.");
#endif




        }

        protected Rectangle GetTitleSafeArea(float percent, GraphicsDeviceManager graphics)
        {
            Rectangle retval = new Rectangle(graphics.GraphicsDevice.Viewport.X,
                graphics.GraphicsDevice.Viewport.Y,
                graphics.GraphicsDevice.Viewport.Width,
                graphics.GraphicsDevice.Viewport.Height);
#if XBOX
        // Find Title Safe area of Xbox 360.
        float border = (1 - percent) / 2;
        retval.X = (int)(border * retval.Width);
        retval.Y = (int)(border * retval.Height);
        retval.Width = (int)(percent * retval.Width);
        retval.Height = (int)(percent * retval.Height);
        return retval;            
#else
            return retval;
#endif
        }



    }
}